package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeAspect {
    @Around("execution(* com.itheima.service.*.*(..))")  // 切点表达式
    public void recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //1.记录时间
        long begin = System.currentTimeMillis();
        //2.调用原始方法
        Object result = joinPoint.proceed();
        //3.记录结束时间
        long end = System.currentTimeMillis();
        log.info(joinPoint.getSignature() + "执行时间为：" + (end - begin) + "毫秒");
    }
}

